import {
  ApiProperty,
  IntersectionType,
  OmitType,
  PartialType,
  PickType,
} from '@nestjs/swagger';
import { IsArray, IsInt, IsString } from 'class-validator';
import { FindListDto } from 'src/modules/find-list.dto';
import { Menu } from '../menu/menu.entity';

export class RoleDto {
  @IsInt()
  @ApiProperty({ type: Number, description: 'id' })
  readonly id: number;

  @IsString()
  @ApiProperty({ type: String, description: '角色名称' })
  readonly role_name: string;

  @IsString()
  @ApiProperty({ type: String, description: '角色权限字符串' })
  readonly role_key: string;

  @IsInt()
  @ApiProperty({ type: Number, description: '显示顺序' })
  readonly sort: number;

  @IsString()
  @ApiProperty({ type: String, description: '数据范围' })
  readonly data_scope: string;

  @IsString()
  @ApiProperty({ type: String, description: '角色状态(1:正常, 0: 停用)' })
  readonly status: string;

  @IsString()
  @ApiProperty({ type: String, description: '是否关联(0:不关联, 1: 关联)' })
  public is_check_strictly: string;

  @IsString()
  @ApiProperty({
    type: String,
    description: '删除标志（0代表存在 1代表删除）',
    default: '0',
  })
  readonly is_delete: string;

  @IsString()
  @ApiProperty({
    type: String,
    description: '备注',
    default: null,
  })
  readonly remark: string;

  @ApiProperty({ type: Date, description: '创建时间', default: null })
  readonly created_date: Date;

  @IsString()
  @ApiProperty({
    type: String,
    description: '创建人',
    default: null,
  })
  readonly created_by: string;

  @ApiProperty({ type: Date, description: '更新时间', default: null })
  readonly updated_date: Date;

  @IsString()
  @ApiProperty({
    type: String,
    description: '更新人',
    default: null,
  })
  readonly updated_by: string;

  @IsArray()
  @ApiProperty({
    type: Array,
    description: '菜单',
    default: [
      {
        id: 1,
      },
    ],
  })
  menus: Menu[];
}

export class FindRoleListDto extends IntersectionType(
  PartialType(FindListDto),
  PartialType(PickType(RoleDto, ['role_name'] as const)),
) {}

export class CreateRoleDto extends PartialType(
  OmitType(RoleDto, ['id', 'created_date', 'updated_date']),
) {}

export class UpdateRoleDto extends PartialType(
  OmitType(RoleDto, ['created_date', 'updated_date']),
) {}
